using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using NSec.Cryptography;

namespace PasswordHasher
{
    internal class Argon2TestWithNesc
    {
        public static string HashPassword(string password, ReadOnlySpan<byte> salt)
        {
            
            Argon2Parameters parameters = new Argon2Parameters()
            {
                MemorySize = 65536,
                NumberOfPasses = 3,
                DegreeOfParallelism = 1
            };
            var argon2 = PasswordBasedKeyDerivationAlgorithm.Argon2id(parameters);

            byte[] hash = new byte[32];
            var passwordBytes = Encoding.UTF8.GetBytes(password);
            argon2.DeriveBytes(passwordBytes, salt,hash); // 输出32字节密钥  

            // 修复 CS8801 错误：确保变量在正确的上下文中声明  
            string storedHash = Convert.ToBase64String(salt) + ":" + Convert.ToBase64String(hash);
            return storedHash;
        }

        
    }
}
